package com.leyou.upload.controller;

import com.leyou.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * springboot nginx zuul默认上传的文件大小都是1MB
     * @param file
     * @return
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadFileToNginx(@RequestParam("file") MultipartFile file){
        String imgUrl = uploadService.uploadFileToNginx(file);
        return ResponseEntity.ok(imgUrl);
    }

    @GetMapping("/signature")
    public ResponseEntity<Map<String,Object>> getSignature(){
        return ResponseEntity.ok(uploadService.getSignature());
    }
}
